/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dialogs.usuario;

import dao.Dao;
import dao.DaoPerfil;
import dialogs.JFramePrincipal;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import libcontrol.model.Emprestimo;
import libcontrol.model.Reserva;
import libcontrol.model.Usuario;
import libcontrol.util.Util;

/**
 *
 * @author filipe
 */
public class JDialogVerUsuario extends javax.swing.JDialog {

    private Usuario usuario;

    /**
     * Creates new form JDialogVerUsuario
     */
    public JDialogVerUsuario(java.awt.Frame parent, boolean modal, Usuario usuario) {
        super(parent, modal);
        initComponents();
        DefaultComboBoxModel model = new DefaultComboBoxModel(new DaoPerfil().list().toArray());
        jComboBoxPerfil.setModel(model);
        preencherCampos(usuario);
        this.usuario = usuario;        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabelNome = new javax.swing.JLabel();
        jLabelEndereco = new javax.swing.JLabel();
        jTextFieldNome = new javax.swing.JTextField();
        jTextFieldEndereco = new javax.swing.JTextField();
        jLabelCpf = new javax.swing.JLabel();
        jFormattedTextFieldCep = new javax.swing.JFormattedTextField();
        jLabelNumero = new javax.swing.JLabel();
        jTextFieldNumero = new javax.swing.JTextField();
        jLabelCidade = new javax.swing.JLabel();
        jTextFieldEmail = new javax.swing.JTextField();
        jLabelUf = new javax.swing.JLabel();
        jFormattedTextFieldCpf = new javax.swing.JFormattedTextField();
        jLabelEmail = new javax.swing.JLabel();
        jFormattedTextFieldTelefone = new javax.swing.JFormattedTextField();
        jLabelTelefone = new javax.swing.JLabel();
        jTextFieldLogin = new javax.swing.JTextField();
        jLabelLogin = new javax.swing.JLabel();
        jTextFieldCidade = new javax.swing.JTextField();
        jLabelVerificaLofin = new javax.swing.JLabel();
        jLabelComplemento = new javax.swing.JLabel();
        jTextFieldComplemento = new javax.swing.JTextField();
        jLabelCep = new javax.swing.JLabel();
        jComboBoxUf = new javax.swing.JComboBox();
        jLabelPerfil = new javax.swing.JLabel();
        jComboBoxPerfil = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableEmprestimos = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableReservas = new javax.swing.JTable();
        jLabelEmprestimos = new javax.swing.JLabel();
        jLabelReservas = new javax.swing.JLabel();
        jButtonExcluirUsuario = new javax.swing.JButton();
        jButtonFechar = new javax.swing.JButton();
        jButtonAlterarUsuario = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setMaximumSize(new java.awt.Dimension(0, 0));

        jLabelNome.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelNome.setText("Nome:");

        jLabelEndereco.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelEndereco.setText("Endereço:");

        jTextFieldNome.setEnabled(false);

        jTextFieldEndereco.setEnabled(false);

        jLabelCpf.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelCpf.setText("CPF:");

        try {
            jFormattedTextFieldCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jFormattedTextFieldCep.setText("");
        jFormattedTextFieldCep.setEnabled(false);

        jLabelNumero.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelNumero.setText("Número:");

        jTextFieldNumero.setEnabled(false);

        jLabelCidade.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelCidade.setText("Cidade:");

        jTextFieldEmail.setEnabled(false);

        jLabelUf.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelUf.setText("UF:");

        try {
            jFormattedTextFieldCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jFormattedTextFieldCpf.setEnabled(false);

        jLabelEmail.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelEmail.setText("Email:");

        try {
            jFormattedTextFieldTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jFormattedTextFieldTelefone.setEnabled(false);

        jLabelTelefone.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelTelefone.setText("Telefone:");

        jTextFieldLogin.setEnabled(false);

        jLabelLogin.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelLogin.setText("Login:");

        jTextFieldCidade.setEnabled(false);

        jLabelVerificaLofin.setText("                 ");

        jLabelComplemento.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelComplemento.setText("Complemento:");

        jTextFieldComplemento.setEnabled(false);

        jLabelCep.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelCep.setText("CEP:");

        jComboBoxUf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Acre", "Alagoas", "Amapá", "Amazonas", "Bahia", "Ceará", "Distrito Federal", "Goiás", "Espírito Santo", "Maranhão", "Mato Grosso", "Mato Grosso do Sul", "Minas Gerais", "Pará ", "Paraiba", "Paraná PR", "Pernambuco", "Piauí", "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul", "Rondônia", "Rorâima", "São Paulo", "Santa Catarina", "Sergipe", "Tocantins" }));
        jComboBoxUf.setEnabled(false);

        jLabelPerfil.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelPerfil.setText("Perfil:");

        jComboBoxPerfil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrador", "Atendente", "Externo" }));
        jComboBoxPerfil.setEnabled(false);

        jTableEmprestimos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cod Obra", "Obra", "Data de Empréstimo", "Prazo de Devolução"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableEmprestimos.setEnabled(false);
        jTableEmprestimos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jTableEmprestimos);
        jTableEmprestimos.getColumnModel().getColumn(0).setResizable(false);
        jTableEmprestimos.getColumnModel().getColumn(1).setResizable(false);
        jTableEmprestimos.getColumnModel().getColumn(1).setPreferredWidth(200);
        jTableEmprestimos.getColumnModel().getColumn(2).setResizable(false);
        jTableEmprestimos.getColumnModel().getColumn(3).setResizable(false);

        jTableReservas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cod Obra", "Obra", "Data da Reserva", "Posição Lista de Reserva"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableReservas.setEnabled(false);
        jTableReservas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(jTableReservas);
        jTableReservas.getColumnModel().getColumn(0).setResizable(false);
        jTableReservas.getColumnModel().getColumn(1).setResizable(false);
        jTableReservas.getColumnModel().getColumn(1).setPreferredWidth(200);
        jTableReservas.getColumnModel().getColumn(2).setResizable(false);
        jTableReservas.getColumnModel().getColumn(3).setResizable(false);

        jLabelEmprestimos.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelEmprestimos.setText("Emprestimos Ativos");

        jLabelReservas.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabelReservas.setText("Reservas Ativas");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelPerfil)
                        .addGap(84, 84, 84)
                        .addComponent(jComboBoxPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(290, 290, 290)
                        .addComponent(jLabelLogin)
                        .addGap(54, 54, 54)
                        .addComponent(jTextFieldLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelNome)
                        .addGap(80, 80, 80)
                        .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23)
                        .addComponent(jLabelCpf)
                        .addGap(18, 18, 18)
                        .addComponent(jFormattedTextFieldCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelEndereco)
                        .addGap(54, 54, 54)
                        .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)
                        .addComponent(jLabelNumero)
                        .addGap(7, 7, 7)
                        .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23)
                        .addComponent(jLabelCep)
                        .addGap(17, 17, 17)
                        .addComponent(jFormattedTextFieldCep, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 801, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelVerificaLofin))
                    .addComponent(jLabelReservas)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 801, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelComplemento)
                            .addComponent(jLabelEmail))
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabelCidade)
                                .addGap(12, 12, 12)
                                .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(23, 23, 23)
                                .addComponent(jLabelUf))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 395, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(36, 36, 36)
                                .addComponent(jLabelTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(27, 27, 27)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jComboBoxUf, 0, 124, Short.MAX_VALUE)
                            .addComponent(jFormattedTextFieldTelefone)))
                    .addComponent(jLabelEmprestimos))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabelPerfil))
                    .addComponent(jComboBoxPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jLabelLogin))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jTextFieldLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabelNome))
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabelCpf))
                    .addComponent(jFormattedTextFieldCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelEndereco)
                    .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelNumero)
                            .addComponent(jLabelCep))))
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelComplemento)
                            .addComponent(jLabelCidade)
                            .addComponent(jLabelUf))))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEmail)
                    .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTelefone)
                    .addComponent(jFormattedTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addComponent(jLabelVerificaLofin)
                        .addGap(82, 82, 82))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelEmprestimos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jLabelReservas)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jButtonExcluirUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/lixeira.png"))); // NOI18N
        jButtonExcluirUsuario.setText("Excluir Usuário");
        jButtonExcluirUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExcluirUsuarioActionPerformed(evt);
            }
        });

        jButtonFechar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/cancelar.png"))); // NOI18N
        jButtonFechar.setText("Fechar");
        jButtonFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFecharActionPerformed(evt);
            }
        });

        jButtonAlterarUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/editar.png"))); // NOI18N
        jButtonAlterarUsuario.setText("Alterar Usuário");
        jButtonAlterarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlterarUsuarioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(jButtonFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(335, 335, 335)
                .addComponent(jButtonExcluirUsuario)
                .addGap(28, 28, 28)
                .addComponent(jButtonAlterarUsuario)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonAlterarUsuario)
                    .addComponent(jButtonExcluirUsuario))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAlterarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlterarUsuarioActionPerformed
        dispose();
        new JDialogCadastrarEditarUsuario((JFrame) getParent(), true, usuario).setVisible(true);
    }//GEN-LAST:event_jButtonAlterarUsuarioActionPerformed

    private void jButtonExcluirUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExcluirUsuarioActionPerformed
        if (usuario.equals(JFramePrincipal.getUsuarioLogado())){
            JOptionPane.showMessageDialog(this, "Você não pode excluir a si mesmo!", "Erro", JOptionPane.ERROR_MESSAGE);
        } else {
            int option = JOptionPane.showConfirmDialog(this, "Tem certeza que deseja excluir o usuário " + usuario + "?",
                    "Confirmar Exclusão", JOptionPane.YES_NO_OPTION);
            if (option == JOptionPane.YES_OPTION) {            
                String menssagem;
                String titulo = "Erro";
                int tipo = JOptionPane.ERROR_MESSAGE;
                if (usuario.hasDebitosPendentes()) {
                    menssagem = "Usuário tem débitos pendentes!";
                } else if (usuario.hasDevolucoesAtrasadas()) {
                    menssagem = "usuário tem devoluções atrasadas!";
                } else {
                    new Dao<Usuario>(Usuario.class).remove(usuario.getId());
                    menssagem = "O usuário foi excluído com sucesso!";
                    titulo = "Sucesso";
                    tipo = JOptionPane.INFORMATION_MESSAGE;
                }
                JOptionPane.showMessageDialog(this, menssagem, titulo, tipo);
                if (tipo == JOptionPane.INFORMATION_MESSAGE) {
                    dispose();
                }
            }
        }

    }//GEN-LAST:event_jButtonExcluirUsuarioActionPerformed

    private void jButtonFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFecharActionPerformed
        dispose();
    }//GEN-LAST:event_jButtonFecharActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAlterarUsuario;
    private javax.swing.JButton jButtonExcluirUsuario;
    private javax.swing.JButton jButtonFechar;
    private javax.swing.JComboBox jComboBoxPerfil;
    private javax.swing.JComboBox jComboBoxUf;
    private javax.swing.JFormattedTextField jFormattedTextFieldCep;
    private javax.swing.JFormattedTextField jFormattedTextFieldCpf;
    private javax.swing.JFormattedTextField jFormattedTextFieldTelefone;
    private javax.swing.JLabel jLabelCep;
    private javax.swing.JLabel jLabelCidade;
    private javax.swing.JLabel jLabelComplemento;
    private javax.swing.JLabel jLabelCpf;
    private javax.swing.JLabel jLabelEmail;
    private javax.swing.JLabel jLabelEmprestimos;
    private javax.swing.JLabel jLabelEndereco;
    private javax.swing.JLabel jLabelLogin;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelNumero;
    private javax.swing.JLabel jLabelPerfil;
    private javax.swing.JLabel jLabelReservas;
    private javax.swing.JLabel jLabelTelefone;
    private javax.swing.JLabel jLabelUf;
    private javax.swing.JLabel jLabelVerificaLofin;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableEmprestimos;
    private javax.swing.JTable jTableReservas;
    private javax.swing.JTextField jTextFieldCidade;
    private javax.swing.JTextField jTextFieldComplemento;
    private javax.swing.JTextField jTextFieldEmail;
    private javax.swing.JTextField jTextFieldEndereco;
    private javax.swing.JTextField jTextFieldLogin;
    private javax.swing.JTextField jTextFieldNome;
    private javax.swing.JTextField jTextFieldNumero;
    // End of variables declaration//GEN-END:variables

    private void preencherCampos(Usuario usuario) {
        jComboBoxPerfil.setSelectedItem(usuario.getPerfil());
        jComboBoxUf.setSelectedItem(usuario.getUf());
        jFormattedTextFieldCep.setText(usuario.getCep());
        jFormattedTextFieldCpf.setText(usuario.getCpf());
        jFormattedTextFieldTelefone.setText(usuario.getTelefone());
        jTextFieldCidade.setText(usuario.getCidade());
        jTextFieldComplemento.setText(usuario.getComplemento());
        jTextFieldEmail.setText(usuario.getEmail());
        jTextFieldEndereco.setText(usuario.getLogradouro());
        jTextFieldLogin.setText(usuario.getLogin());
        jTextFieldNome.setText(usuario.getNome());
        jTextFieldNumero.setText(usuario.getNumero());
        DefaultTableModel model = (DefaultTableModel) jTableEmprestimos.getModel();
        model.setRowCount(0);
        Object[] rowData = new Object[4];
        for (Emprestimo e : usuario.getEmprestimosAtivos()) {
            rowData[0] = e.getExemplar().getId();
            rowData[1] = e.getExemplar();
            rowData[2] = Util.dateToString(e.getDataEmprestimo());
            rowData[3] = Util.dateToString(e.getPrazoDevolucao());
            model.addRow(rowData);
        }
        jTableEmprestimos.setModel(model);
        model = (DefaultTableModel) jTableReservas.getModel();
        model.setRowCount(0);
        rowData = new Object[4];
        for (Reserva r : usuario.getReservasAtivas()) {
            rowData[0] = r.getObra().getId();
            rowData[1] = r.getObra().getTitulo();
            rowData[2] = Util.dateToString(r.getDataReserva());
            rowData[3] = r.getLugarLista();
            model.addRow(rowData);
        }
        jTableReservas.setModel(model);
    }
}
